
/* 第一版写法 */
function createPerson(firstName, lastName) {
  var obj = {};
  obj.firstName = firstName
  obj.lastName = lastName
  obj.fullName = firstName + lastName
  obj.sayHi = function () {
    console.log('hello我的名字叫做', obj.fullName)
  }
  return obj
}


createPerson('king','sen').sayHi()


/* 第二种写法，Person 构造函数 */
function Person(firstName, lastName) {
  this.firstName = firstName
  this.lastName = lastName
  this.fullName = firstName + lastName
  this.sayHi = function () {
    console.log('hello我的名字叫做',this.fullName)
  }
}


var person1 = new Person('曾','庆森')
person1.sayHi()

var person2 = new Person('李','鑫')
person2.sayHi()






/* 错误写法： fullName中有obj，会先执行右侧{} ,此时还没有obj*/
// var obj = {
//   firstName: "曾",
//   lastName: '庆森',
//   fullName : obj.firstName + obj.lastName
// }
// console.log(obj.fullName);


